<?php 
?>
<div id="sidebar">

	<?php 
	
	
	// cookie doesn't exist
	if(!key_exists("sfc_score", $_COOKIE)) {
		?>
		<div id="sidebar_no_cookie">
			<form id="new_cookie_form" method="post" action="">
				<h1>Hey There!</h1>
				<h3>Did you know you are getting points for visiting this website?</h3>
				<p>Enter your name and we can keep track of your awesome progress!</p>
				<label>Your name:</label>
				<input type="text" name="cookie_name" class="input_text border-box"/>
				<input id="submit" type="submit" value="Go!" class="submit_go">
			</form>
			
		</div>
		<?php
	}
	// cookie exists
	else {
		sfc_add_view();
		$progress = sfc_get_personal_progress();
		//sfc_print_array($progress);
		
		$quiz_sum = count($progress[5]);
		?>
		<div id="sidebar_progress">
			<h2>Your Progress</h2>
			<p class="sidebar_progress_score"><?php echo $progress[2][0]; ?></p>
			<div class="sidebar_progress_badges">
				<div class="sidebar_badge">
					<img src="<?php echo get_template_directory_uri(); ?>/images/badges/happy_box.png">
					<p>Create an account</p>
				</div>
				<div class="sidebar_badge">
					<?php 
					if($progress[4][0] >= 5)
						echo '<img src="' . get_template_directory_uri() . '/images/badges/trophy_newbie.png">';
					else 
						echo '<img src="' . get_template_directory_uri() . '/images/badges/trophy_newbie-bw.png">';
					?>
					<p>Visit the website 5 times</p>
				</div>
				<div class="sidebar_badge">
					<?php 
					if($progress[4][0] >= 10)
						echo '<img src="' . get_template_directory_uri() . '/images/badges/trophy_10.png">';
					else 
						echo '<img src="' . get_template_directory_uri() . '/images/badges/trophy_10-bw.png">';
					?>
					<p>Visit the website 10 times</p>
				</div>
				<div class="sidebar_badge">
					<?php 
					if($progress[4][0] >= 25)
						echo '<img src="' . get_template_directory_uri() . '/images/badges/trophy_25.png">';
					else 
						echo '<img src="' . get_template_directory_uri() . '/images/badges/trophy_25-bw.png">';
					?>
					<p>Visit the website 25 times</p>
				</div>
				<div class="sidebar_badge">
					<?php 
					if($progress[4][0] >= 50)
						echo '<img src="' . get_template_directory_uri() . '/images/badges/trophy_50.png">';
					else 
						echo '<img src="' . get_template_directory_uri() . '/images/badges/trophy_50-bw.png">';
					?>
					<p>Visit the website 50 times</p>
				</div>
				<div class="sidebar_badge">
					<?php 
					if($quiz_sum >= 1)
						echo '<img src="' . get_template_directory_uri() . '/images/badges/star-4.png">';
					else 
						echo '<img src="' . get_template_directory_uri() . '/images/badges/star-4-bw.png">';
					?>
					<p>Take 1 quiz</p>
				</div>
				<div class="sidebar_badge">
					<?php 
					if($quiz_sum >= 10)
						echo '<img src="' . get_template_directory_uri() . '/images/badges/star-3.png">';
					else 
						echo '<img src="' . get_template_directory_uri() . '/images/badges/star-3-bw.png">';
					?>
					<p>Take 10 quizzes</p>
				</div>
				<div class="sidebar_badge">
					<?php 
					if($quiz_sum >= 20)
						echo '<img src="' . get_template_directory_uri() . '/images/badges/star-2.png">';
					else 
						echo '<img src="' . get_template_directory_uri() . '/images/badges/star-2-bw.png">';
					?>
					<p>Take 20 quizzes</p>
				</div>
				<div class="sidebar_badge">
					<?php 
					if($quiz_sum >= 40)
						echo '<img src="' . get_template_directory_uri() . '/images/badges/star-1.png">';
					else 
						echo '<img src="' . get_template_directory_uri() . '/images/badges/star-1-bw.png">';
					?>
					<p>Take every quiz possible!</p>
				</div>
			</div>
		</div>
		<?php 
	}
	
	
	?>
	<div id="sidebar_leaderboard">
		<h2>Leaderboard</h2>
		
		<?php 
			$leaderboard = sfc_get_leaderboard();
			foreach($leaderboard as $name => $score) {
				?>
					<div class="sidebar_leader_entry">
						<p class="sidebar_leaderboard_name"><?php echo $name?></p>
						<p class="sidebar_leaderboard_score"><?php echo $score?></p>
					</div>
				<?php 
			}		
		?>
	
	</div>
	
	
	<div id="sidebar_games">
		<h2>Games</h2>
		
		<?php 	
		
		
		if(have_posts()): while(have_posts()): the_post(); 
		
		
		
		?>
	
	</div>
	<?php 
	
?>	
</div>